/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// ptable.hpp - PegTable class definition.
//
// Author: Kenneth G. Maxwell
//
// Copyright (c) 1997-2002 Swell Software 
//              All Rights Reserved.
//
// Unauthorized redistribution of this source code, in whole or part,
// without the express written permission of Swell Software
// is strictly prohibited.
//
// PEG Version:  1.8.0
// File Version: 1.8.0.2
//
// Notes:
//
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

#ifndef _PEGTABLE_
#define _PEGTABLE_

struct TableCellInfo
{
    TableCellInfo() 
    {
        pChild = NULL;
        pNext = NULL; 
        RowSpan = 1; 
        ColSpan = 1; 
        Style = TCF_HCENTER | TCF_VCENTER;
    }
    PegThing *pChild;
    TableCellInfo *pNext;
    PEGINT Row;
    PEGINT Col;
    PEGINT RowSpan;
    PEGINT ColSpan;
    PEGULONG Style;    // 0x00000001 bit is for ForceFit, upper byte for justification
};


class PegTable : public PegWindow
{
    public:

        PegTable(PegRect &Rect, PEGINT Rows, PEGINT Cols);
        virtual ~PegTable();

        virtual void Draw(const PegRect &Invalid);
        virtual void DrawChildren(const PegRect &Invalid);
        virtual void DrawGrid(void);

        PegThing *GetCellClient(PEGINT Row, PEGINT Col);
        PEGINT GetCellPadding(void) {return mCellPad;}
        void GetCellSpan(PEGINT Row, PEGINT Col, 
                           PEGINT *pRowSpan, PEGINT *pColSpan);
        PEGULONG GetCellStyle(PEGINT Row, PEGINT Col);
        PEGINT GetColumns(void) {return mCols;}
        PEGINT GetForcedColWidth(PEGINT Col);
        PEGINT GetForcedRowHeight(PEGINT Row);
        PEGINT GetGridWidth(void) {return mGridWidth;}
        PEGBOOL GetRowCol(PegThing *pChild, PEGINT *pRow, PEGINT *pCol);
        PEGINT GetRows(void) {return mRows;}

        virtual void Layout(void);
        virtual void Reconfigure(PEGINT Rows, PEGINT Cols,
                                 PEGINT GridWidth, PEGINT CellPad);
        PegThing *RemoveCellClient(PEGINT Row, PEGINT Col);

        virtual void SetCellClient(PEGINT Row, PEGINT Col, PegThing *pChild,
                                   PEGINT RowSpan = 1, PEGINT ColSpan = 1, 
                                   PEGULONG Style = TCF_HCENTER | TCF_VCENTER);
        virtual void SetCellPadding(PEGINT Pad) {mCellPad = Pad;}
        virtual void SetColWidth(PEGINT Col, PEGINT Width, 
                                 PEGBOOL Force = FALSE);

        void SetGridWidth(PEGINT Width = PEG_FRAME_WIDTH);
        virtual void SetRowHeight(PEGINT Row, PEGINT Height, 
                                  PEGBOOL Force = FALSE);

    protected:

        PEGBOOL CellSpansCol(PEGINT Row, PEGINT Col);
        PEGBOOL CellSpansRow(PEGINT Row, PEGINT Col);

        PEGINT *mpCellHeights;
        PEGINT *mpCellWidths;
        TableCellInfo *mpCellInfo;
        PEGINT mCellPad;
        PEGINT mGridWidth;
        PEGINT mRows;
        PEGINT mCols;
};

#endif

